
/**
 * 新增简历与编辑简历的添加标签js
 * 
 * */
		//接收选中的标签
        var testMap={};
        
		$("#add_label").click(function(){
			$("#main-center").show(250);
		});
		$("#main-center").mouseleave(function(){
		   $(this).hide(250);
		});
		
		
		//查询一级标签
		function sublable(){
			var json={
				isSublable:'1'
			};
			$.ajax({
				url: "com.recruit.talent.label.selectParentsLabel.biz.ext",
				type:'POST',
				data:json,
				success:function(data){
					for(var i=0;i<data.sublabel.length;i++){
						$(".list-group").append("<li class='list-group-item' id='one_label"+i+"' value='"+data.sublabel[i].id+"' onmouseover=gettext(\'one_label"+i+"\',this.value)>"+data.sublabel[i].lable+"<i class='layui-icon xe623'>&#xe623;</i></li>");
					}
					$("#one_label0").css("background-color","#ffffff");
					$("#one_label0").css("border-right-color","#ffffff");
					$("#one_label0 i").css("color","#417fd6");
				}
			});
		}
		
		//
		function gettext(id,label_id){
			//触发时改变样式
			$(".list-group-item").css("background-color","#f2f2f2");
			$(".list-group-item").css("border-right-color","#ddd");
			$(".xe623").css("color","#616161");
			
			$("#"+id).css("background-color","#ffffff");
			$("#"+id).css("border-right-color","#ffffff");
			$("#"+id+" i").css("color","#417fd6");
			
			secondLevel(label_id);
			
		}
		
		
		
		//查询二三级标签
		function secondLevel(id){
			var json={
				lable_id:id
			};
			$.ajax({
				url: "com.recruit.talent.label.secondLevelLabel.biz.ext",
				type:'POST',
				data:json,
				success:function(data){
					$("#content-Two_label").empty();//清空数据
					 for(var i=0;i<data.result.length;i++){
						var content_Two_label ="<div class='panel-heading'>"
							+"<h6 class='panel-title'>"
							+"<a data-toggle='collapse' data-parent='#accordion' href='#collapseOne"+i+"'>"+data.result[i].lable+" >>"
							+"</a></h6></div>"
							+"<div id='collapseOne"+i+"' class='panel-collapse collapse in'>"
							+"<div class='panel-body' id='panel_label'><ul>";
							var recruitSublable = data.result[i].recruitSublable;//将二级标签中的子标签赋值到recruitSublable
							//判断  recruitSublable 是否空
							if(typeof(recruitSublable) != "undefined"){
								//如果  recruitSublable 长度大于0则循环加载子标签
								if(recruitSublable.length>0){
									for(var j=0;j<recruitSublable.length;j++){
										content_Two_label +="<li><a data='"+recruitSublable[j].id+"'><span>"+recruitSublable[j].lable+"</span></a></li>";
									}
								}
							}
							+"</ul></div></div></div>";
							
						$("#content-Two_label").append(content_Two_label);
						
					}
					 	var value="";
						var text="";
					  $("#panel_label ul li a").each(function(index){
						  $(this).click(function(){
							 /*value=$(this).children('input').val();*/
							  //获取所点击的A标签的值
							 value =$(this).attr("data");
						     text =$(this).children('span').html();
						     var num=0;
						     for(var key in testMap){
						    	 if(key == value){
						    		 num++;
						    	 }
						     }
						     if(num == 0){
					    		 testMap[value] = text;
					    		 //拼接标签
						    	 $("#content_label2").append("<span class='label label-info' data='"+value+"' id='"+value+"'>"+text+"<i class='layui-icon xe617'  onclick='delete_label(this)'  data='"+value+"'>&#x1006;</i></span>");
						     }
						  });
					  });
				}
			});
		}
		
		//提交数据到数据库
    	function submit(){
    		var leaderName =$("#leaderName").val();//招聘负责人
    		var leaderId =$("#leaderId").val();
    		var name =$("#name").val();//人才名
    		var intentionPosition =$("#intentionPosition").val();//意向职位
    		var phone =$("#phone").val();//电话
    		var intentionPositionInterior =$("#intentionPositionInterior").val();//意向职位类别
    		var email =$("#email").val();//邮箱
    		var expectationPay =$("#expectationPay").val();//期望薪资
    		var study =$("#study").val();//学历
    		var birthTime =$("#birthTime").val();//出生日期
    		var talentpoolSex =$("#talentpoolSex").val();//性别
    		var orgcentre =$("#orgBranch").val();//面试部门
    		var orgcentreId=$("#orgBranch").attr("alias");
    		var L1 = $("#orgBranch").attr("l1");
    		var L2 = $("#orgBranch").attr("l2");
    		var L3 = $("#orgBranch").attr("l3");
    		var L4 = $("#orgBranch").attr("l4");
    		var L1name = $("#orgBranch").attr("l1name");
    		var L2name = $("#orgBranch").attr("l2name");
    		var L3name = $("#orgBranch").attr("l3name");
    		var L4name = $("#orgBranch").attr("l4name");

    		
    		var interviewPositon =$("#interviewPositon").val();//面试职位
    		var abandonLink =$("#abandonLink").val();//放弃环节
    		var abandonCondition =$("#abandonCondition").val();//放弃原因
    		var abandonCause =$("#abandonCause").val();//具体放弃情况描述
    		var supplier =$("#supplier").val();//渠道
    		var channel =$("#channel").val();//供应商
    		var state=$("#state").val();//状态
    		var isInworkorder=$("#isInworkorder").val();//是否已在工单
    		
    		//地址拼接
    		var address ="";
				if($('#province').val()!=""){
					address=$('#province').val();
				}
				if($("#city").val()!=""){
					address=$('#province').val()+"-"+$("#city").val();
				}
				if($("#district").val()!=""){
					address=$('#province').val()+"-"+$("#city").val()+"-"+$("#district").val();
				}
			
			var address_2 ="";
				if($('#province_2').val()!=""){
					address_2=$('#province_2').val();
				}
				if($("#city_2").val()!=""){
					address_2=$('#province_2').val()+"-"+$("#city_2").val();
				}
				if($("#district_2").val()!=""){
					address_2=$('#province_2').val()+"-"+$("#city_2").val()+"-"+$("#district_2").val();
				}
			
			var nowSite ="";
				if($('#province_nowSite').val()!=""){
					nowSite=$('#province_nowSite').val();
				}
				if($("#city_nowSite").val()!=""){
					nowSite=$('#province_nowSite').val()+"-"+$("#city_nowSite").val();
				}
				if($("#district_nowSite").val()!=""){
					nowSite=$('#province_nowSite').val()+"-"+$("#city_nowSite").val()+"-"+$("#district_nowSite").val();
				}
			
    		
    		
    		//获取标签id
    		var obj="";
    		for(var key1 in testMap){
					obj +=key1+",";
				} 
    		
    		//获取上传地址
    		var accessory_url="";
    		var accessory_name="";
    		var accessory_path="";
    		 $(".afiles").each(function(i,obj){
    			 accessory_url += getCaption($(obj).attr("href"))+"^";
    			 accessory_name += $(obj).text()+"^";
    			 accessory_path += $(obj).attr("data")+"^";
    		 });
    		
    		var json={
				leaderName:leaderName,	
				leaderId:leaderId,
				name:name,
				intentionPosition:intentionPosition,
				phone:phone,
				intentionPositionInterior:intentionPositionInterior,
				email:email,
				expectationPay:expectationPay,
				address:address,
				address_2:address_2,
				study:study,
				birthTime:birthTime,
				talentpoolSex:talentpoolSex,
				nowSite:nowSite,
				orgcentre:orgcentre,
				orgcentreId:orgcentreId,
				l1:L1,
				l1name:L1name,
				l2:L2,
				l2name:L2name,
				l3:L3,
				l3name:L3name,
				l4:L4,
				l4name:L4name,
				abandonLink:abandonLink,
				abandonCondition:abandonCondition,
				abandonCause:abandonCause,
				supplier:supplier,
				channel:channel,
				state:state,
				isInworkorder:isInworkorder,
				interviewPositon:interviewPositon,
				obj:obj,
				accessory_url:accessory_url,
				accessory_name:accessory_name,
				accessory_path:accessory_path
			};
			$.ajax({
				url: "com.recruit.talent.talent.insertTalent.biz.ext",
				type:'POST',
				data:json,
				success:function(data){
					if(data.success=="ok"){
						layer.msg('保存成功');
					}else{
						layer.msg('保存失败');
					}
				}
			});
    	}
    	
    	
    	//提交数据到数据库
    	function updateAndAdd(id){
    		var leaderName =$("#leaderName").val();//招聘负责人
    		var leaderId =$("#leaderId").val();
    		var name =$("#name").val();//人才名
    		var intentionPosition =$("#intentionPosition").val();//意向职位
    		var phone =$("#phone").val();//电话
    		var intentionPositionInterior =$("#intentionPositionInterior").val();//意向职位类别
    		var email =$("#email").val();//邮箱
    		var expectationPay =$("#expectationPay").val();//期望薪资
    		var study =$("#study").val();//学历
    		var birthTime =$("#birthTime").val();//出生日期
    		var talentpoolSex =$("#talentpoolSex").val();//性别
    		var orgcentre =$("#orgBranch").val();//面试部门
    		var orgcentreId=$("#orgBranch").attr("alias");
    		var L1 = $("#orgBranch").attr("l1");
    		var L2 = $("#orgBranch").attr("l2");
    		var L3 = $("#orgBranch").attr("l3");
    		var L4 = $("#orgBranch").attr("l4");
    		var L1name = $("#orgBranch").attr("l1name");
    		var L2name = $("#orgBranch").attr("l2name");
    		var L3name = $("#orgBranch").attr("l3name");
    		var L4name = $("#orgBranch").attr("l4name");

    		
    		var interviewPositon =$("#interviewPositon").val();//面试职位
    		var abandonLink =$("#abandonLink").val();//放弃环节
    		var abandonCondition =$("#abandonCondition").val();//放弃原因
    		var abandonCause =$("#abandonCause").val();//具体放弃情况描述
    		var supplier =$("#supplier").val();//渠道
    		var channel =$("#channel").val();//供应商
    		var state=$("#state").val();//状态
    		var isInworkorder=$("#isInworkorder").val();//是否已在工单
    		
    		//地址拼接
    		var address ="";
				if($('#province').val()!=""){
					address=$('#province').val();
				}
				if($("#city").val()!=""){
					address=$('#province').val()+"-"+$("#city").val();
				}
				if($("#district").val()!=""){
					address=$('#province').val()+"-"+$("#city").val()+"-"+$("#district").val();
				}
			
			var address_2 ="";
				if($('#province_2').val()!=""){
					address_2=$('#province_2').val();
				}
				if($("#city_2").val()!=""){
					address_2=$('#province_2').val()+"-"+$("#city_2").val();
				}
				if($("#district_2").val()!=""){
					address_2=$('#province_2').val()+"-"+$("#city_2").val()+"-"+$("#district_2").val();
				}
			
			var nowSite ="";
				if($('#province_nowSite').val()!=""){
					nowSite=$('#province_nowSite').val();
				}
				if($("#city_nowSite").val()!=""){
					nowSite=$('#province_nowSite').val()+"-"+$("#city_nowSite").val();
				}
				if($("#district_nowSite").val()!=""){
					nowSite=$('#province_nowSite').val()+"-"+$("#city_nowSite").val()+"-"+$("#district_nowSite").val();
				}
			
    		
    		
    		//获取标签id
    		var obj="";
    		for(var key1 in testMap){
					obj +=key1+",";
				} 
    		
    		//获取上传地址
    		var accessory_url="";
    		var accessory_name="";
    		var accessory_path="";
    		 $(".afiles").each(function(i,obj){
    			 accessory_url += getCaption($(obj).attr("href"))+"^";
    			 accessory_name += $(obj).text()+"^";
    			 accessory_path += $(obj).attr("data")+"^";
    		 });
    		
    		var json={
    			resume_id:id,
				leaderName:leaderName,	
				leaderId:leaderId,
				name:name,
				intentionPosition:intentionPosition,
				phone:phone,
				intentionPositionInterior:intentionPositionInterior,
				email:email,
				expectationPay:expectationPay,
				address:address,
				address_2:address_2,
				study:study,
				birthTime:birthTime,
				talentpoolSex:talentpoolSex,
				nowSite:nowSite,
				orgcentre:orgcentre,
				orgcentreId:orgcentreId,
				l1:L1,
				l1name:L1name,
				l2:L2,
				l2name:L2name,
				l3:L3,
				l3name:L3name,
				l4:L4,
				l4name:L4name,
				abandonLink:abandonLink,
				abandonCondition:abandonCondition,
				abandonCause:abandonCause,
				supplier:supplier,
				channel:channel,
				state:state,
				isInworkorder:isInworkorder,
				interviewPositon:interviewPositon,
				obj:obj,
				accessory_url:accessory_url,
				accessory_name:accessory_name,
				accessory_path:accessory_path
			};
			$.ajax({
				url: "com.recruit.talent.talent.updateResumeAndAddTalent.biz.ext",
				type:'POST',
				data:json,
				success:function(data){
					if(data.success=="ok"){
						layer.msg('保存成功');
					}else{
						layer.msg('保存失败');
					}
				}
			});
    	}
		
		
		//删除已选好的标签
		function delete_label(numId){
			var id =$(numId).attr("data");
			/*$(numId).parent('span').empty();*/
			$(numId).parent().empty();
			delete testMap[id];
			var obj="#content_label2 #"+id;
			$(obj).remove();//清除
		}
		
		
		//编辑简历页面已存在标签删除
		function delete_label2(numId){
			var id =$(numId).attr("data");
			var label_id=$(numId).attr("opp");
			var str=$(numId).parent().text();//获取标签名字
			var name=str.substring(0,str.length-1);//去掉第一个字符
			var json={
				id:id	
			};
			layer.open({
		        type: 1
		        ,offset:'auto' 
		        ,id: 'layerDemo'
		        ,content: '<div style="padding: 11px 73px;">标签名为：'+name+'</div><div style="text-align: center;" >是否确定要删除此标签？</div>'
		        ,closeBtn: false
		        ,btn:['确定','关闭']
		        ,btnAlign: 'c' //按钮居中
		        ,shade: 0 //不显示遮罩
		        ,closeBtn: false//不显示关闭图标
		        ,yes: function(index){
		        	$.ajax({
			  			url:"com.recruit.talent.label.deleteLabel.biz.ext",
		  				type:"POST",
		  				data:json,
		  				success:function(data){
		  					if(data.success=='ok'){
		  						layer.msg("删除成功！");
		  						layer.close(index);//关闭页面
		  						$(numId).parent().empty();
		  						delete testMap[label_id];
		  						var obj="#content_label2 #"+label_id;
		  						$(obj).remove();//清除
		  					}else{
		  						layer.msg("删除失败！");
		  					};
		  				}
			  		});	
		        }
		        ,btn2: function(){
		          layer.closeAll();//关闭页面
		        }
		  }); 
		}
		
		
		//删除附件
		function resumnedelete(id,filepath,name){
			var json = {
				id:id,
				filepath:filepath
			};
			if(id==0){
				$.ajax({
					url : "com.recruit.interpolation.interpolationindex.deleteResume.biz.ext",
					type : 'POST',
					async: false,
					data : json,
					success : function(data) {
						
					}
				});
			}else{
				layer.open({
			        type: 1
			        ,offset:'auto' 
			        ,id: 'layerDemo'
			        ,content: '<div style="padding: 9px 75px 0px;">附件名：'+name+'</div><div style="text-align: center;"><br>是否确定要删除该附件？</div>'
			        ,closeBtn: false
			        ,btn:['确定','关闭']
			        ,btnAlign: 'c' //按钮居中
			        ,shade: 0 //不显示遮罩
			        ,closeBtn: false//不显示关闭图标
			        ,yes: function(index){
			        	$.ajax({
							url : "com.recruit.interpolation.interpolationindex.deleteResume.biz.ext",
							type : 'POST',
							async: false,
							data : json,
							success : function(data) {
								var obj="#recruitAcc"+id;
								$(obj).remove();//清除
								layer.msg('附件删除成功');
								layer.close(index);//关闭页面
								var text=$("#file_upload").html();
					        	if(text=="" || text==null){
					        		 $("#resumes").css("display","none");
					        	}
							}
						});
			        }
			        ,btn2: function(){
			          layer.closeAll();//关闭页面
			        }
			  }); 
			}
		}
		
		//当附件上传未提交时删除附件
		 $("#resumes").css("display","none");
		 function delectfile(upid,url){
			 resumnedelete(0,url);//删除服务器上的附件
	            var id="#"+upid.id;
	        	$(id).remove();//清除当前id
	        	var text=$("#file_upload").html();
	        	if(text=="" || text==null){
	        		 $("#resumes").css("display","none");
	        	}
     	}
		
		 
		 
		   var isPass=true;//标识是否通过验证
		   var isPassMsg="";//非空验证提示输出
		   var arr=[];
	   	//失去焦点验证
	   	function validator(){
	   		isPassMsg="";
	   		isPass=true;
	   		arr=[];
	   		//姓名
	  		 	if($('.name').val()==null || $('.name').val()=="" ){
	           	$(".name").css("border","1px solid red");
	           	isPassMsg+="请输入姓名,";
	           	isPass=false;
	           }else{
	           	$(".name").css("border","1px solid #ccc");
	           }
	   		
	   		//意向职位
	  		 	if($('.intentionPosition').val()==null || $('.intentionPosition').val()=="" ){
	           	$(".intentionPosition").css("border","1px solid red");
	           	isPassMsg+="请输入意向职位,";
	           	isPass=false;
	           }else{
	           	$(".intentionPosition").css("border","1px solid #ccc");
	           }
	   		
	   		//意向职位类别
	  		 	if($('.intentionPositionInterior').val()==null || $('.intentionPositionInterior').val()=="" ){
	           	$(".intentionPositionInterior").css("border","1px solid red");
	           	isPassMsg+="请选择意向职位类别,";
	           	isPass=false;
	           }else{
	           	$(".intentionPositionInterior").css("border","1px solid #ccc");
	           }
	   		
	   		//电话
				var phone=/^1\d{10}$/;//电话正则
	  		 	if($('.phone').val()==null || $('.phone').val()=="" || !phone.test($(".phone").val())){
	           	$(".phone").css("border","1px solid red");
	           	isPassMsg+="请输入正确的手机号码,";
	           	isPass=false;
	           }else{
	           	$(".phone").css("border","1px solid #ccc");
	           }
	  		 	
				//邮箱
				var email=/^([a-zA-Z0-9_\.\-])+\@(([a-z0-9\-])+\.)+([a-z0-9]{2,4})+$/;//邮箱正则
	  		 	if($('.email').val()==null || $('.email').val()=="" || !email.test($(".email").val())){
	           	$(".email").css("border","1px solid red");
	           	isPassMsg+="请输入正确的邮箱格式-如：XXX@qq.com,";
	           	isPass=false;
	           }else{
	           	$(".email").css("border","1px solid #ccc");
	           }
	  		 	
	  		 	//期待薪资
	  		 	if($('#expectationPay').val()==null || $('#expectationPay').val()==""){
	           	$("#expectationPay").css("border","1px solid red");
	           	isPassMsg+="请选择期待薪资,";
	           	isPass=false;
	           }else{
	           	$("#expectationPay").css("border","1px solid #ccc");
	           }
	  		 	
	   		 //工作意向地的省份
	           if($('.province_1').val()==null || $('.province_1').val()=="" || $('.city_1').val()==null || $('.city_1').val()==""){
	           	$(".province_1").css("border","1px solid red");
	           	$(".city_1").css("border","1px solid red");
	           	isPassMsg+="请选择工作意向地,";
	           	isPass=false;
	           }else{
	           	$(".province_1").css("border","1px solid #ccc");
	           	$(".city_1").css("border","1px solid #ccc");
	           }
	           //学历
	  		 	if($('.study').val()==null || $('.study').val()=="" ){
	           	$(".study").css("border","1px solid red");
	           	isPassMsg+="请选择学历,";
	           	isPass=false;
	           }else{
	           	$(".study").css("border","1px solid #ccc");
	           }
	   		
	            //现居地的省份
	           if($('.province_nowSite').val()==null || $('.province_nowSite').val()=="" || $('.city_nowSite').val()==null || $('.city_nowSite').val()==""){
	           	$(".province_nowSite").css("border","1px solid red");
	           	$(".city_nowSite").css("border","1px solid red");
	           	isPassMsg+="请选择现居地,";
	           	isPass=false;
	           }else{
	           	$(".province_nowSite").css("border","1px solid #ccc");
	           	$(".city_nowSite").css("border","1px solid #ccc");
	           }
	           
	           //渠道
	  		 	if($('.channel').val()==null || $('.channel').val()==""){
	           	$(".channel").css("border","1px solid red");
	           	isPassMsg+="请选择渠道,";
	           	isPass=false;
	           }else{
	           	$(".channel").css("border","1px solid #ccc");
	           }
	  		 	
	  		 	//添加标签
	  		 	if($("#content_label2").html()==null || $("#content_label2").html()==""){
	  		 		isPassMsg+="标签至少选择一个,";
		           	isPass=false;
	  		 	}
	  		 	
	  		 	//文件上传
	  		 	if($("#file_upload").html()==null || $("#file_upload").html()==""){
	  		 		isPassMsg+="附件至少要上传一个";
		           	isPass=false;
	  		 	}
	  		 	
	  		 	arr=isPassMsg.split(",");
	   	} 
